package com.itheima.health.controller;

import com.itheima.health.common.MessageConst;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.Setmeal;
import com.itheima.health.service.SetMealService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/mobile/setmeal")
public class SetMealController {

    @DubboReference
    private SetMealService setMealService;

    @GetMapping("/getSetmeal")
    public Result getSetMeal(){
        /*
        * @Date: 2:12 下午 2021/1/10
        * @param: []
        * @return: com.itheima.health.entity.Result
        * @Description: 查询所有套餐
        */
        List<Setmeal> setMealList = setMealService.findAll();
        log.info("[体检预约-套餐-getSetMeal] - findAll: {}",setMealList);
        if (setMealList==null){
            return new Result(false, MessageConst.QUERY_SETMEAL_FAIL);
        }
        return new Result(true,MessageConst.QUERY_SETMEAL_SUCCESS,setMealList);
    }


    @GetMapping("/findById")
    public Result findById(Integer id){
        /*
        * @Date: 2:50 下午 2021/1/10
        * @param: [id]
        * @return: com.itheima.health.entity.Result
        * @Description: 根据id获取套餐详细信息
        */
        log.info("[套餐-套餐详情页-前端传入数据] - id: {}",id);
        Setmeal setmeal = setMealService.findById(id);
        log.info("[套餐-套餐详情页-后端返回数据] - SetMeal: {}",setmeal);

        if (setmeal==null){
            return new Result(false,MessageConst.QUERY_SETMEAL_FAIL);
        }
        return new Result(true,MessageConst.QUERY_SETMEAL_SUCCESS,setmeal);
    }
}
